package com.k2.gulimall.member.service.impl;

import com.k2.gulimall.member.vo.MemberCollectSpu;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.k2.common.utils.PageUtils;
import com.k2.common.utils.Query;

import com.k2.gulimall.member.dao.MemberCollectSpuDao;
import com.k2.gulimall.member.entity.MemberCollectSpuEntity;
import com.k2.gulimall.member.service.MemberCollectSpuService;


@Service("memberCollectSpuService")
public class MemberCollectSpuServiceImpl extends ServiceImpl<MemberCollectSpuDao, MemberCollectSpuEntity> implements MemberCollectSpuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<MemberCollectSpuEntity> queryWrapper = new QueryWrapper<MemberCollectSpuEntity>();
        if (params.get("memberId")!=null&&params.get("memberId").toString().length()>0) {
            queryWrapper.eq("member_id", params.get("memberId"));
        }
        IPage<MemberCollectSpuEntity> page = this.page(
                new Query<MemberCollectSpuEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    public boolean delMemberCollectSpu(MemberCollectSpu memberCollectSpu){
        QueryWrapper<MemberCollectSpuEntity> queryWrapper = new QueryWrapper<MemberCollectSpuEntity>();
        if (memberCollectSpu.getMemberid()!=null&&memberCollectSpu.getMemberid().toString().length()>0&&memberCollectSpu.getSpuid()!=null&&memberCollectSpu.getSpuid().toString().length()>0) {
            queryWrapper.eq("member_id", memberCollectSpu.getMemberid());
            queryWrapper.eq("spu_id", memberCollectSpu.getSpuid());
            return this.remove(queryWrapper);
        }else{
            return false;
        }
    };

}